<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        td{
            border: 1px solid black;
        }

    </style>
</head>

<body>
    <button id="tijiao">提交</button>
         <table id="user" > 
        <td>商品ID</td>
        <td>商品名称</td>
        <td>商品价格</td>
        <td>商品创作</td>
        <td>商品照片</td>
        <td>商品详情</td>
        <td>商品进口</td>
    </table>
    <div id="ad1" >
    商品详情:<input type="text" id=" goodSdetail"><br>
    商品照片:<input type="text" id="goodsPhoto"><br>
    商品名称:<input type="text" id="goodsName"><br>
    商品价格:<input type="text" id="goodsPrice"><br>
    商品时间:<input type="text" id="goodsCreationTime"><br>
    商品库存:<input type="text" id="goodslnventory"><br>
    <button onclick="add1()">确认</button>
    </div>
</body>
<script src="jquery-3.7.1.js"></script>
<script>

    $("#tijiao").click(function () {
        $.ajax({
            url: "http://172.16.106.87:8080/ShowGoods",
            type: "get",
            success: function (e) {
                console.log(e.data);
                var sout=e.data
                let obj = ""
                sout.forEach(data => {
                    obj+= `<tr>
            <td>${data.goodsId}</td>
            <td>${data.goodsPhoto}</td>
            <td>${data.goodsName}</td>
            <td>${data.goodsPrice}</td>
            <td>${data.goodsCreationTime}</td>
            <td>${data.goodslnventory}</td>
            <td>${data.goodSdetail}</td>
            <td>
            <button id="zeng" onclick="xinzeng">新增</button>
            <button onclick="del(${data.goodsId})"> 删除</button>
            </td>
            </tr>
        `
                        
                })
                $("#user").append(obj);
            }
        })
    })
    function del(id1){
        $.ajax({
        url:"http://172.16.106.87:8080/delGoods",
        type:"get",
        data:{
            id:id1
        },
        success:function(v){
            alert(v)
            location.reload()
        }
    })
    }
    function add1(){
       $.ajax({
        url:"http://172.16.106.87:8080/addGoods",
        type:"get",
        data:{
            goodSdetail:$("#goodSdetail").val(),
            goodsPhoto :$("#goodsPhoto").val(),
            goodsName: $("#goodsName").val(),
            goodsPrice: $("#goodsPrice").val(),
            goodsCreationTime: $("#goodsCreationTime").val(),
            goodslnventory: $("#goodslnventory").val(),
      },
        success:function(a){
            console.log(a);
           
        }
    }) 
    }
</script>

</html>